﻿using BaseCore;
using BaseCore.RemoteServiceInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Lifetime;
using System.Text;
using System.Threading;

namespace RemoteService
{
    public class CalculaterService : MarshalByRefObject , ICalculaterService
    {
        int _nIndex = 0;
        public static CalculaterService Instance = null;

        public CalculateRes Calculate(CalculateInfo info)
        {
            Interlocked.Increment(ref _nIndex);
            CalculateRes ret = new CalculateRes();
            ret.nValue = info.p1 + info.p2;
            ret.nIndex = _nIndex;

            return ret;
        }

        /// <summary>
        /// 生存期控制
        /// </summary>
        /// <returns></returns>
        public override object InitializeLifetimeService()
        {
            Instance = this;

            ILease lease = (ILease)base.InitializeLifetimeService();

            if(lease.CurrentState == LeaseState.Initial)
            {
                lease.InitialLeaseTime = TimeSpan.FromDays(2000);
            }
            return lease;
        }
    }
}
